package com.project.service.impl;

import com.project.bean.OrderBean;
import com.project.bean.OrderInfoBean;
import com.project.mapper.IOrderMapper;
import com.project.service.IOrderInfoService;
import com.project.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
@Transactional
public class OrderServiceImpl implements IOrderService {
    @Autowired
    private IOrderMapper orderMapper;
    @Autowired
    private IOrderInfoService orderInfoService;
    @Override
    public void add(OrderBean orderBean, List<OrderInfoBean> orderInfoBeanList) {
        orderMapper.insert(orderBean);
        for (OrderInfoBean o:orderInfoBeanList
             ) {
            o.setOrderId(orderBean.getId());
        }
        orderInfoService.addMore(orderInfoBeanList);
    }

    @Override
    public void updateStatus(Integer orderId, String status) {
        OrderBean orderBean = orderMapper.selectById(orderId);
        orderBean.setStatus(status);
        orderMapper.updateById(orderBean);
    }
}
